/*=====================================================================================================================
                    Copyright(c) 2010 Geometric PLM Software Corp. All rights reserved.
                             Unpublished - All rights reserved
=======================================================================================================================
File description:
    Filename: tc_encrypt.c
    Module  : Common module.

        This file implement the encrypt/decipher of string.

=======================================================================================================================
Date               Name              Description of Change
19-Jan-2010        Penn,Xie          Initialize creation
$HISTORY$
=====================================================================================================================*/

#ifdef BUILD_IMAN
#include <iman_string.h>

#else
#include <fclasses\tc_string.h>

#endif

#include <base_utils\mem.h>

void GENC_encrypt( char *str, int key )
{
    int size = 0, i = 0, value = 0;
    if (str == NULL)
        return;

    size = (int)strlen(str);
    for( i = 0; i < size; ++i)
    {
        value = str[i] - key;
        if ( value < 33)
        {
            str[i] = 126 - (33 - value); 
        }
        else
        {
            str[i] = value;
        }
    }
}

void GENC_decrypt( char *str, int key )
{
    int size = 0, i = 0, value = 0;
    if (str == NULL)
        return;

    size = (int)strlen(str);
    for( i = 0;i < size; ++i)
    {
        value = str[i] + key;
        if ( value > 126 )
        {
            str[i] = 33 + (value - 126);
        }
        else
        {
            str[i] = value;
        }
    }
}
